package main

import (
	"fmt"
	"strings"
)

// 给一组单词，用 - 连接起来，保证每条连接起来的字符串
// 长度不超过给定的值

func wordBreak(words []string, maxLen int) []string {
	res := []string{}

	for i := 0; i < len(words); i++ {
		if len(words[i]) > maxLen {
			continue
		}

		remainingLen := maxLen
		cnt := 0

		for i < len(words) {
			if remainingLen-len(words[i]) < 0 {
				break
			}
			cnt += 1

			remainingLen = remainingLen - len(words[i]) - 1
			i++
		}
		res = append(res, strings.Join(words[i-cnt:i], "-"))
		i--
	}
	return res
}

func main() {
	words := []string{"The", "day", "began", "as", "still", "as", "the"}
	// words := strings.Split(strings.Join(lines, " "), " ")
	fmt.Println(wordBreak(words, 10))
}
